package rdd

import org.apache.spark.broadcast.Broadcast
import org.apache.spark.rdd.RDD
import org.apache.spark.{SparkConf, SparkContext}

object RDD_BroadcastValue {
  def main(args: Array[String]): Unit = {
    val conf = new SparkConf()
    conf.setMaster("local")
    conf.setAppName("RDD_BroadcastValue")

    val sc = new SparkContext(conf)
    val broads: Broadcast[Int] = sc.broadcast(3)

    val numListRDD: RDD[Int] = sc.parallelize(List(1, 2, 3, 4, 5))
    val resultRDD: RDD[Int] = numListRDD.map(
      x => {
        val broadValue = broads.value
        x * broadValue
      }
    )
    println(resultRDD.collect().mkString(","))


    sc.stop()
  }
}
